import { Router } from 'express';
import analyticsController from '@controllers/analytics.controller';
import { authenticate } from '@middleware/auth';

const router = Router();

/**
 * Analytics Routes
 */

/**
 * @swagger
 * /analytics/statistics:
 *   get:
 *     summary: Get overall analytics statistics
 *     tags: [Analytics]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: Overall statistics retrieved successfully
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                   example: true
 *                 data:
 *                   type: object
 *                   properties:
 *                     totalAlerts:
 *                       type: number
 *                       example: 1542
 *                     totalTickets:
 *                       type: number
 *                       example: 856
 *                     avgResolutionTime:
 *                       type: number
 *                       example: 4.5
 *                     mttr:
 *                       type: number
 *                       description: Mean Time To Resolution (hours)
 *                       example: 2.3
 *       401:
 *         description: Unauthorized
 */
router.get('/statistics', authenticate, analyticsController.getStatistics);

/**
 * @swagger
 * /analytics/alert-trend:
 *   get:
 *     summary: Get alert trend data
 *     tags: [Analytics]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: period
 *         schema:
 *           type: string
 *           enum: [day, week, month]
 *           default: week
 *         description: Time period for trend analysis
 *     responses:
 *       200:
 *         description: Alert trend data retrieved successfully
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                   example: true
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       date:
 *                         type: string
 *                         format: date
 *                       count:
 *                         type: number
 *                       severity:
 *                         type: object
 *       401:
 *         description: Unauthorized
 */
router.get('/alert-trend', authenticate, analyticsController.getAlertTrend);

/**
 * @swagger
 * /analytics/ticket-distribution:
 *   get:
 *     summary: Get ticket distribution data
 *     tags: [Analytics]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: Ticket distribution data retrieved successfully
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                   example: true
 *                 data:
 *                   type: object
 *                   properties:
 *                     byStatus:
 *                       type: object
 *                       properties:
 *                         open:
 *                           type: number
 *                         in_progress:
 *                           type: number
 *                         resolved:
 *                           type: number
 *                         closed:
 *                           type: number
 *                     byPriority:
 *                       type: object
 *                       properties:
 *                         low:
 *                           type: number
 *                         medium:
 *                           type: number
 *                         high:
 *                           type: number
 *                         critical:
 *                           type: number
 *       401:
 *         description: Unauthorized
 */
router.get('/ticket-distribution', authenticate, analyticsController.getTicketDistribution);

/**
 * @swagger
 * /analytics/alert-severity:
 *   get:
 *     summary: Get alert severity statistics
 *     tags: [Analytics]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: Alert severity statistics retrieved successfully
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                   example: true
 *                 data:
 *                   type: object
 *                   properties:
 *                     critical:
 *                       type: number
 *                       example: 12
 *                     warning:
 *                       type: number
 *                       example: 45
 *                     info:
 *                       type: number
 *                       example: 98
 *       401:
 *         description: Unauthorized
 */
router.get('/alert-severity', authenticate, analyticsController.getAlertSeverity);

/**
 * @swagger
 * /analytics/response-time:
 *   get:
 *     summary: Get response time statistics
 *     tags: [Analytics]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: days
 *         schema:
 *           type: integer
 *           default: 7
 *         description: Number of days to analyze
 *     responses:
 *       200:
 *         description: Response time statistics retrieved successfully
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                   example: true
 *                 data:
 *                   type: object
 *                   properties:
 *                     avgResponseTime:
 *                       type: number
 *                       description: Average response time in minutes
 *                       example: 15.5
 *                     medianResponseTime:
 *                       type: number
 *                       example: 12.0
 *                     trend:
 *                       type: array
 *                       items:
 *                         type: object
 *       401:
 *         description: Unauthorized
 */
router.get('/response-time', authenticate, analyticsController.getResponseTime);

/**
 * @swagger
 * /analytics/performance:
 *   get:
 *     summary: Get performance report
 *     tags: [Analytics]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: startDate
 *         schema:
 *           type: string
 *           format: date
 *         description: Start date for the report
 *       - in: query
 *         name: endDate
 *         schema:
 *           type: string
 *           format: date
 *         description: End date for the report
 *     responses:
 *       200:
 *         description: Performance report retrieved successfully
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                   example: true
 *                 data:
 *                   type: object
 *                   properties:
 *                     alertMetrics:
 *                       type: object
 *                     ticketMetrics:
 *                       type: object
 *                     systemMetrics:
 *                       type: object
 *                     recommendations:
 *                       type: array
 *                       items:
 *                         type: string
 *       401:
 *         description: Unauthorized
 */
router.get('/performance', authenticate, analyticsController.getPerformanceReport);

export default router;
